home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 2: CDPD 1 / Almathera Ten on Ten - Disc 2: CDPD 1.iso / pd / 076-100 / 091 / util / vstring.c < prev   
C/C++ Source or Header  |  1995-03-13  |  3KB  |  186 lines

  1. /*LINTLIBRARY*/
  2. #include <stdio.h>
  3.  
  4. #include "adltypes.h"
  5. #include "virtmem.h"
  6.  
  7. #define MINTEMP (-10000) /* Minimum temp value */
  8.  
  9. static char
  10.    *temptab,        /* Storage for temporary strings */
  11.    *savetab;        /* Storage for saved strings */
  12.  
  13. static int32
  14.     *ndxtab,        /* Index page area */
  15.     numc = 1L;        /* Number of characters in strings */
  16.  
  17. int16
  18.     strdirty = 0,    /* Do we need to flush the strings? */
  19.     numtemp  = 1,    /* Number of temporary chars */
  20.     *num_save,        /* Number of saved chars */
  21.     nums     = 1;    /* Number of string table entries */
  22.  
  23.  
  24. struct pagetab
  25.     strpages;        /* Page table for virtmem */
  26.  
  27.  
  28. int16
  29. numstr()
  30. {
  31.     return nums;
  32. }
  33.  
  34.  
  35. int32
  36. numchar()
  37. {
  38.     return numc;
  39. }
  40.  
  41.  
  42. int16
  43. newtstr( s )
  44. char
  45.     *s;
  46. {
  47.     int16
  48.     t;
  49.  
  50.     strcpy( &temptab[ numtemp ], s );
  51.     t = numtemp;
  52.     numtemp += strlen( s ) + 1;
  53.     return -t;
  54. }
  55.  
  56.  
  57. int16
  58. vs_save( n )
  59. int16
  60.     n;
  61. {
  62.     int16 t;
  63.     char *virtstr();
  64.  
  65.     if( n >= 0 )
  66.     return n;
  67.     strcpy( &savetab[ *num_save ], virtstr( n ) );
  68.     t = *num_save;
  69.     *num_save += strlen( &savetab[ *num_save ] ) + 1;
  70.     return MINTEMP - t;
  71. }
  72.  
  73.  
  74. vsflush()
  75. {
  76.     if( strdirty )
  77.     vm_flush( &strpages );
  78.     numtemp = 1;
  79. }
  80.  
  81.  
  82. encode( s )
  83. char
  84.     *s;
  85. {
  86.     while( *s )
  87.     *s++ ^= CODE_CHAR;
  88. }
  89.  
  90.  
  91. decode( s )
  92. char
  93.     *s;
  94. {
  95.     while( *s )
  96.     *s++ ^= CODE_CHAR;
  97. }
  98.  
  99.  
  100. int16
  101. newstr( s )
  102. char
  103.     *s;
  104. {
  105.     char
  106.     t[ 512 ];
  107.  
  108.     ndxtab[ nums ] = numc;    /* Put current char index into str tab */
  109.     strcpy( t, s );        /* Get a working copy of s */
  110.     encode( t );        /* Make it unreadable by human eyes */
  111.     s = t;
  112.     while( *s )            /* Write the string out */
  113.     vm_put8( *s++, numc++, &strpages );
  114.     vm_put8( (char)0, numc++, &strpages );
  115.     return nums++;
  116. }
  117.  
  118.  
  119. static char *
  120. tvirt( id )
  121. int16
  122.     id;
  123. {
  124.     if( id <= MINTEMP )
  125.     return &savetab[ MINTEMP - id ];
  126.     else
  127.     return &temptab[ -id ];
  128. }
  129.  
  130.  
  131. char *
  132. virtstr( id )
  133. int16
  134.     id;
  135. {
  136.     int32
  137.     adr;            /* Address of the string in the file */
  138.     char
  139.     ch,            /* Current char of the string */
  140.     *s;            /* Pointer to current char */
  141.     static char
  142.     tvs[ 512 ];        /* Save area */
  143.  
  144.     if( id < 0 )
  145.     /* This was a temp string - return one. */
  146.     return tvirt( id );
  147.  
  148.     adr = ndxtab[ id ];
  149.     s = tvs;
  150.  
  151.     /* Read in the string */
  152.     for( ch=vm_get8( adr++, &strpages ); ch; ch=vm_get8( adr++, &strpages ) )
  153.     *s++ = ch;
  154.     *s = '\0';
  155.  
  156.     decode( tvs );
  157.     return tvs;
  158. }
  159.  
  160.  
  161. vsinit( strf, stri, init, temp, save, ns, ndx )
  162. int
  163.     strf;                /* The swap file        */
  164. int32
  165.     stri;                /* Offset into the swap file    */
  166. int16
  167.     init;                /* Read the first page in?    */
  168. char
  169.     *temp;                /* Temp string area        */
  170. char
  171.     *save;                /* Save string area        */
  172. int16
  173.     *ns;                /* Area for # of save strings    */
  174. int32
  175.     *ndx;                /* Index table            */
  176. {
  177.     strdirty = !init;
  178.     vm_init( strf, stri, &strpages, strdirty );
  179.     num_save = ns;
  180.     temptab = temp;
  181.     savetab = save;
  182.     ndxtab = ndx;
  183. }
  184.  
  185. /*** EOF vstring.h ***/
  186.